package router

import (
	//"com.yy.api/server/controller/container"
	"com.yy.api/server/controller/instance"
	"fmt"
	"github.com/beego/beego/v2/server/web"
)

const (
	MethodPost              = "post"
	MethodGet               = "get"
	MethodPut               = "put"
	MethodDelete            = "delete"
	ApiPrefix               = "/api"
	ApiVersion              = "/v1"
	ApiPath                 = ApiPrefix + ApiVersion
	CreateInstanceApi       = ApiPath + "/instance/create"
	ListContainerApi        = ApiPath + "/container/list"
	HasContainerApi         = ApiPath + "/container/has"
	ReleaseContainerApi     = ApiPath + "/container/release"
	HealthCheckContainerApi = ApiPath + "/container/health-check"
)

type Router struct {
	//container container.Container
	instanceController instance.ControllerImpl
}

func NewRouter() *Router {
	return &Router{
		//container: container.NewContainer(),
		instanceController: instance.NewInstanceController(),
	}
}

type route struct {
	method, path, handler string
}

var containerRoutes = []route{
	//	{MethodPost, CreateInstanceApi, "CreateInstance"},
	{MethodPost, ListContainerApi, "ContainerList"},
	{MethodPost, HasContainerApi, "HasContainer"},
	{MethodPost, ReleaseContainerApi, "ReleaseContainer"},
	{MethodPost, HealthCheckContainerApi, "HealthCheckContainer"},
}
var instanceRoutes = []route{
	{MethodPost, CreateInstanceApi, "Create"},
}

//	func (router *Router) registerContainerRoutes(routes []route) {
//		for _, r := range routes {
//			web.Router(r.path, &router.container, fmt.Sprintf("%s:%s", r.method, r.handler))
//		}
//	}
func (router *Router) registerInstanceRoutes(routes []route) {
	for _, r := range routes {
		web.Router(r.path, &router.instanceController, fmt.Sprintf("%s:%s", r.method, r.handler))
	}
}
func (router *Router) Route() {
	//router.registerContainerRoutes(containerRoutes)
	router.registerInstanceRoutes(instanceRoutes)
}

func init() {
	r := NewRouter()
	r.Route()
}
